<?php
    require "config.php";
    try{
        if($_POST){
            $dbh = dbConnect();
            $username = $_POST["username"];
            $password = $_POST["password"];
            if($username != ""){
                $sql = "SELECT * FROM `admin-users` WHERE name = '$username'";
                $sth = $dbh->query($sql);
                $result = $sth->fetch();
                if($password == $result["password"]){
                    header("Location:after-message.php");
                }else{
                    echo "<script>alert('对不起，密码错误')</script>";  
                }
            }
        }
    }catch(PDOException $e){
        print("error:".$e->getMessage());
        die();
    }   
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>后台管理系统登录</title>
    <link rel="stylesheet" href="./css/after-login.css">
</head>

<body>
    <div class="form-wrap">
        <h1 style="color: white;">后端管理系统</h1>
        <form action="after-login.php" method="POST">
            <input type="text" name="username" placeholder="请输入管理员账户名称">
            <input type="password" name="password" placeholder="请输入登录密码">
            <input type="submit" value="登录">
        </form>
    </div>
</body>

</html>